package com.molichuxing.services.infrastructure.service;

import com.molichuxing.framework.dto.Paged;
import com.molichuxing.framework.service.RootService;
import com.molichuxing.services.infrastructure.dto.request.create.ContractCreateDto;
import com.molichuxing.services.infrastructure.dto.response.ContractDto;
import com.molichuxing.services.property.ContractStatusEnum;
import com.molichuxing.services.property.ContractTypeEnum;
import com.molichuxing.services.property.DocumentTypeEnum;

import java.time.LocalDate;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 合同表 服务类
 * </p>
 *
 * @author zhaopenghui
 * @since 2019-09-11
 */
public interface ContractService extends RootService {

    /**
     * 合同分页列表
     *
     * @param map
     * @param pageNum
     * @param pageSize
     * @return
     * @throws Exception
     */
    public Paged<ContractDto> getContractPage(Map<String, Object> map, Integer pageNum, Integer pageSize) throws Exception;

    /**
     * 子合同列表
     *
     * @param mainOrderCode
     * @return
     * @throws Exception
     */
    public List<ContractDto> getSubContractList(Long mainOrderCode) throws Exception;

    /**
     * 获取合同/单据信息
     *
     * @param orderCode    订单号
     * @param documentType 文件类型
     * @return
     * @throws Exception
     */
    public List<ContractDto> getContractList(Long orderCode, DocumentTypeEnum documentType) throws Exception;

    /**
     * 合同添加
     *
     * @param contractCreateDto
     * @return
     * @throws Exception
     */
    public Integer createContract(ContractCreateDto contractCreateDto) throws Exception;

    /**
     * 合同列表
     *
     * @param orderCode
     * @param contractType
     * @return
     */
    public List<ContractDto> getContractListByOrderCode(Long orderCode, Integer contractType);

    /**
     * 通过合同编号查询
     *
     * @param contractCode
     * @return
     */
    public List<ContractDto> getListByContractCode(String contractCode);

    /**
     * 批量添加合同
     *
     * @param list
     * @return
     */
    public Boolean createContractBatch(List<ContractDto> list);

    /**
     * 获取合同
     *
     * @param id
     * @return
     */
    public ContractDto getContractDtoById(Integer id);

    /**
     * 修改合同到期日期
     *
     * @param orderCode
     * @param endTime
     * @return
     */
    public Boolean modifyContractEndTime(Long orderCode, LocalDate endTime);

    /**
     * 根据订单号修改状态
     *
     * @param orderCode
     * @param contractStatus
     * @return
     */
    public Boolean modifyStatusByOrderCode(Long orderCode, Integer contractStatus);

    /**
     * 根据主订单号修改状态
     *
     * @param mainOrderCode
     * @param contractStatus
     * @return
     */
    public Boolean modifyStatusByMainOrderCode(Long mainOrderCode, Integer contractStatus);

    /**
     * 合同编号是否存在
     *
     * @param contractCode
     * @return
     */
    public Boolean getContractCodeExist(String contractCode);

    /**
     * 通过订单查询合同
     *
     * @param orderCode
     * @param contractType
     * @return
     */
    public List<ContractDto> getContractByOrderCode(Long orderCode, Integer contractType);

    /**
     * 通过订单查询合同
     *
     * @param orderCodeList
     * @param contractType
     * @return
     */
    public Map<Long, List<ContractDto>> getContractMapByOrderCode(List<Long> orderCodeList, Integer contractType);

    /**
     * 根据状态获取数量
     *
     * @return
     */
    public Map<Integer, Integer> getContractCountByStatus();

    /**
     * 修改合同状态
     *
     * @param orderCode        订单号
     * @param contractStatus   修改后状态
     * @param contractTypeList 合同类型list
     * @return
     */
    public boolean modifyStatus(Long orderCode, ContractStatusEnum contractStatus,
                                List<ContractTypeEnum> contractTypeList);

}